package halfDivide;

public class mountainTopDivide {
    public static void main(String[] args) {
        int[] nums={4,5,6,7,1,2};
        System.out.println(findPeakElement(nums));
    }
    public static int findPeakElement(int[] nums) {
        if (nums==null || nums.length==0){
            return 0;
        }

        int start =0;
        int end =nums.length-1;
        int mid;
        while(start+1<end){
            mid=start+(end-start)/2;
            if (nums[mid]<nums[mid-1]){
                end=mid;
            }else if(nums[mid]<nums[mid+1]){
                start=mid;
            }else{
                return mid;
            }
        }
        return nums[start]>nums[end]?start:end;
    }
}
